package Model;

import Controller.MapGenerator;

import java.awt.*;
import java.net.URL;

public class Tile
{

	/**
	 * ENUM for the Tile's Biome
	 * @author Chris
	 */
	public enum Biome
	{
        SNOW("snow", new Color(189, 189, 189,255)),
        MOUNTAIN("mountain", new Color(161, 109, 55,255)),
        PLAIN("plain", new Color(11, 221, 82,255)),
        FOREST("forest", new Color(247, 255, 246,255)),
        RIVER("river", new Color(0,173,229,255)),
        DESERT("desert", new Color(202,156,115,255)),
        OCEAN("ocean", new Color(6, 162, 254,255));

        private String biomeName;
        private Color color;

        Biome(String myBiome, Color myColor)
        {
            this.biomeName = myBiome;
            this.color = myColor;
        }

        public String toString() 
        {
            return biomeName;
        }

        public Color getColor()
        {
            return color;
        }

    }
	
	private Biome biome;
	private double height;
    public int alpha;
	
	/**
	 * CONSTRUCTOR for the Tile
	 * @param h the Tile's height
	 */
	public Tile(double h)
	{
        this.height = h;
        this.initializeBiome();
        this.calculateAlpha();
	}

    /**
     * Called when the tile is created. Sets the tile's initial biome depending on its height.
     */
    public void initializeBiome()
    {
        if(this.height <= MapGenerator.oceanHeight)
        {
            this.biome = Biome.OCEAN;
        }
        else if(this.height <= MapGenerator.plainsHeight)
        {
            this.biome = Biome.PLAIN;
        }
        else if(this.height <= MapGenerator.mountainHeight)
        {
            this.biome = Biome.MOUNTAIN;
        }
        else
        {
            this.biome = Biome.SNOW;
        }
    }

    public void calculateAlpha()
    {
        System.out.println("BAM "+this.getBiome().toString());
        if(this.biome == Biome.SNOW)
        {
            this.alpha = (int)(255 - (this.height - MapGenerator.mountainHeight));
        }
        else if(this.biome == Biome.MOUNTAIN)
        {
            this.alpha = (int)(255 - (this.height - MapGenerator.plainsHeight));
        }
        else if(this.biome == Biome.PLAIN)
        {
            this.alpha = (int)(255 - (this.height - MapGenerator.oceanHeight));
        }
        else if(this.biome == Biome.OCEAN)
        {
            this.alpha = (int)(255 - (this.height - MapGenerator.minHeight));
        }
    }

	//GETTERS and SETTERS
	
	public Biome getBiome()
	{
		return this.biome;
	}
	
	public void setBiome(Biome newBiome)
	{
		this.biome = newBiome;
	}

    public double getHeight()
    {
        return this.height;
    }

	public void setHeight(int d)
	{
		this.height = d;
	}
	
}
